package com.lmf.handler;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器类：拦截用户请求
public class MyInterceptor implements HandlerInterceptor {

    /**
     *  验证登录系统：
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("111111执行了preHandle方法");
        String logName="";
//        Object attr = request.getSession().getAttribute("name");
        Object attr = request.getParameter("name");
        //获取用户名
        if (attr != null) {
            logName=(String) attr;
        }
        //验证用户名,是否符合要求
        if ( ! "zs".equals(logName)) {
            request.getRequestDispatcher("/tips.jsp").forward(request,response);
            return false;
        }
        //zs登录
        return true;
    }
}
